package user;

import Dao.communityDao;
import Dao.communityDaoImpl;
import been.Health;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
@WebServlet(value = "/findInformation")
public class findInformationServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        communityDao dao = new communityDaoImpl();
        Health health = null;
        String message = null;
        int health_id=0;
        String health_idParam=request.getParameter("health_id");
        if(health_idParam==null){
            message="id不能为空";
            request.setAttribute("message",message);
            request.getRequestDispatcher("/WEB-INF/user/findHealthInformation.jsp").forward(request,response);
        }
        else{
            health_id=Integer.parseInt(health_idParam);
            try {
                health=dao.findHealthByHealthId(health_id);
                request.setAttribute("health",health);
                request.getRequestDispatcher("/WEB-INF/user/showHealthInformation.jsp").forward(request,response);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
